package com.anche.cywebnew.Service.exchangeManager.impl;

import com.anche.cywebnew.DAO.enchangeManager.DataMapper;
import com.anche.cywebnew.DAO.enchangeManager.MessageLogMapper;
import com.anche.cywebnew.Pojo.exchangeManager.YyDataBase;
import com.anche.cywebnew.Pojo.exchangeManager.message.MessageLog;
import com.anche.cywebnew.Service.exchangeManager.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service
public class DataServiceImpl implements DataService {

    @Autowired
    DataMapper dataMapper;

    @Autowired
    MessageLogMapper messageLogMapper;

    @Override
    public int insertOne(YyDataBase yyDataBase) {
        int count = dataMapper.insert(yyDataBase);
        return count;
    }

    @Override
    public List<YyDataBase> selectList() {
//        QueryWrapper<YyDataBase> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("status","0").or().eq("status","2")
//                .orderByAsc("jhsj");
        List<YyDataBase> yyDataBases = dataMapper.selectList();
        return yyDataBases;
    }

    @Override
    public List<YyDataBase> selectList2() {
//        QueryWrapper<YyDataBase> queryWrapper = new QueryWrapper<>();
//        queryWrapper.isNull("status").or().eq("status","");
//
//        List<YyDataBase> yyDataBases = dataMapper.selectList(queryWrapper);
        List<YyDataBase> yyDataBases = dataMapper.selectListByStatusIsNullOrEmpty();

        return yyDataBases;
    }


    @Override
    public int updateOne(YyDataBase data) {
        int i = dataMapper.updateById(data);
        return i;
    }

    @Override
    public int deleteList(LocalDateTime sevenDaysAgo) {

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String time = sevenDaysAgo.format(formatter);
        int count = dataMapper.deleteList(time);
        return count;
    }


    @Override
    public String selectDataBase(YyDataBase yyDataBase) {
        String exit = "";
        YyDataBase yyDataBase1 = dataMapper.selectById(yyDataBase.getId());
        if (yyDataBase1!=null){
            exit = "error";
        }else {
            exit = "success";
        }
        return exit;
    }

    @Override
    public YyDataBase selectDataBaseById(String id) {

        return dataMapper.selectById(id);
    }

    @Override
    public void insetMessageLog(MessageLog messageLog) {
//        messageLogMapper.insert(messageLog);
        messageLogMapper.insertMessageLog(messageLog);
    }

    @Override
    public int selectMessageNumByCylsh(String cylsh) {
        return dataMapper.selectMessageNumByCylsh(cylsh);
    }

    @Override
    public void updateMessageNumByCylsh(String cylsh, int messagenum,String lszt) {
        dataMapper.updateMessageNumByCylsh(cylsh,messagenum,lszt);
    }

    @Override
    public String selectMessageStatusByCylsh(String cylsh) {
        return dataMapper.selectMessageStatusByCylsh(cylsh);
    }
}
